from pydantic import BaseModel
from typing import List, Optional, Generic, TypeVar
from datetime import datetime

# 泛型类型变量，用于统一响应封装
T = TypeVar('T')

class BaseResponse(BaseModel, Generic[T]):
    """统一响应封装"""
    code: int
    msg: str
    data: Optional[T] = None

class PaginationResponse(BaseModel, Generic[T]):
    """分页响应封装"""
    code: int
    msg: str
    data: List[T]
    total: int
    page: int
    page_size: int
    total_pages: int

class ChatRequest(BaseModel):
    message: str
    session_id: Optional[str] = None

class ChatResponse(BaseModel):
    session_id: str
    message: str
    is_finished: bool

class ConversationList(BaseModel):
    id: int
    session_id: str
    title: str
    created_at: datetime
    message_count: int

class MessageDetail(BaseModel):
    id: int
    content: str
    is_user: bool
    is_positive: Optional[bool] = None
    feedback_content: Optional[str] = None
    created_at: datetime

class ConversationDetail(BaseModel):
    id: int
    session_id: str
    title: str
    created_at: datetime
    messages: List[MessageDetail]

class FeedbackRequest(BaseModel):
    message_id: int
    is_positive: bool
    feedback_content: Optional[str] = None

class RecommendedQuestions(BaseModel):
    questions: List[str]